package com.catemanagement.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FormatUtil {

    public static final String DATE_TIME = "yyyy-MM-dd HH:mm:ss";

    public static final String DATE = "yyyy-MM-dd";
    
    public static final String DATE_YEAR = "yyyy";
    
    public static final String DATE_YEAR_MONTH = "yyyy-MM";

    public static final String TIME = "HH:mm:ss";

    public static String formatDate(Date date, String pattern) {
        SimpleDateFormat sdf = getDateFormat(pattern);
        return sdf.format(date);
    }

    public static Date parse(String date, String pattern) throws ParseException {
        if (date == null) {
            return null;
        }
        SimpleDateFormat sdf = getDateFormat(pattern);
        return sdf.parse(date);
    }

    private static SimpleDateFormat getDateFormat(String pattern) {
        return new SimpleDateFormat(pattern);
    }
}
